package com.etl.dataflow.scheduler.admin.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.etl.dataflow.scheduler.admin.validation.Add;
import com.etl.dataflow.scheduler.admin.validation.Update;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <p>
 * 任务信息
 * </p>
 *
 * @author dx
 * @since 2022-04-24
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("dataflow_task_info")
public class DataflowTaskInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * CRON表达式
     */
    @TableField("cron_expr")
    @NotBlank(groups = Add.class)
    private String cronExpr;

    /**
     * 主键,使用ID_WORKER策略,全局唯一ID
     */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @NotNull(groups = Update.class)
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long id;

    /**
     * 任务名称
     */
    @NotBlank(groups = Add.class)
    @TableField("name")
    private String name;

    /**
     * 源数据源ID
     */
    @NotNull(groups = Add.class)
    @TableField("src_ds_id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long srcDsId;

    /**
     * 目标数据源ID
     */
    @NotNull(groups = Add.class)
    @TableField("dst_ds_id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long dstDsId;

    /**
     * 源表名
     */
    @NotBlank(groups = Add.class)
    @TableField("src_table_name")
    private String srcTableName;

    /**
     * 目标表名
     */
    @NotBlank(groups = Add.class)
    @TableField("dst_table_name")
    private String dstTableName;

    /**
     * 查询sql
     */
    @NotBlank(groups = Add.class)
    @TableField("select_sql")
    private String selectSql;

    /**
     * JDBC fetch_size
     */
    @NotNull(groups = Add.class)
    @TableField("fetch_size")
    private Integer fetchSize;

    /**
     * 缓冲区大小
     */
    @NotNull(groups = Add.class)
    @TableField("buffer_size")
    private Integer bufferSize;

    /**
     * 任务启动前拦截器SpringBean名称
     */
    @TableField("launch_interceptor")
    private String launchInterceptor;

    /**
     * 读后拦截器SpringBean名称
     */
    @TableField("after_read_interceptor")
    private String afterReadInterceptor;

    /**
     * 写后拦截器SpringBean名称
     */
    @TableField("after_write_interceptor")
    private String afterWriteInterceptor;

    public enum TimerState {
        /**
         * 已禁用定时任务
         */
        DISABLED,

        /**
         * 已启用定时任务
         */
        ENABLED
    }

    /**
     * 定时任务状态，用来标记是否开启定时任务
     */
    @TableField("timer_state")
    private Integer timerState;

    /**
     * 所属任务组id
     */
    @TableField("group_id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long groupId;

    /**
     * 创建用户id
     */
    @TableField("creator_id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long creatorId;

    /**
     * 插入时间
     */
    @TableField(value = "idt", fill = FieldFill.INSERT)
    private LocalDateTime idt;

    /**
     * 更新时间
     */
    @TableField(value = "udt", fill = FieldFill.UPDATE)
    private LocalDateTime udt;


}
